package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;

import com.seanchenxi.gwt.wordpress.domain.model.Author;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class AuthorsResponseHandler extends BaseResponseHandler<ArrayList<Author>>{
	@Override
	public ArrayList<Author> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<Author> authors = new ArrayList<Author>();
		for(Object obj : (ArrayList<?>)object){
			Author author = ModelFactory.ToAuthor(obj);
			if(author!=null && !authors.contains(author)){ 
				authors.add(author);
			}
		}
			
		return authors;
	}
}
